package com.probox.modules.controller.order;

import cn.hutool.core.util.ObjectUtil;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.utils.poi.ExcelUtil;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.order.OrderShipDeliver;
import com.probox.common.entity.service.order.IOrderShipDeliverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 订单发货信息Controller
 *
 * @author hds
 * @date 2021-06-07
 */
@RestController
@RequestMapping("/order/deliver")
public class OrderShipDeliverController extends BaseController {
    @Autowired
    private IOrderShipDeliverService orderShipDeliverService;

    /**
     * 查询订单发货信息列表
     */
    @PreAuthorize(hasPermi = "order:deliver:list")
    @GetMapping("/list")
    public TableDataInfo list(OrderShipDeliver orderShipDeliver) {
        if(ObjectUtil.isEmpty(orderShipDeliver.getStoreId())){
            orderShipDeliver.setStoreId(SecurityUtils.getStoreId());
        }
        startPage();
        List<OrderShipDeliver> list = orderShipDeliverService.queryList(orderShipDeliver);
        return getDataTable(list);
    }

    /**
     * 导出订单发货信息列表
     */
    @PreAuthorize(hasPermi = "order:deliver:export")
    @Log(title = "订单发货信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderShipDeliver orderShipDeliver) throws IOException {
        List<OrderShipDeliver> list = orderShipDeliverService.queryList(orderShipDeliver);
        ExcelUtil<OrderShipDeliver> util = new ExcelUtil<OrderShipDeliver>(OrderShipDeliver.class);
        util.exportExcel(response, list, "订单发货信息数据");
    }

    /**
     * 获取订单发货信息详细信息
     */
    @PreAuthorize(hasPermi = "order:deliver:query")
    @GetMapping(value = "/{deliverUid}")
    public AjaxResult getInfo(@PathVariable("deliverUid") Long deliverUid) {
        return AjaxResult.success(orderShipDeliverService.selectOrderShipDeliverById(deliverUid));
    }

    /**
     * 新增订单发货信息
     */
    @PreAuthorize(hasPermi = "order:deliver:add")
    @Log(title = "订单发货信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderShipDeliver orderShipDeliver) {
        return toAjax(orderShipDeliverService.insertOrderShipDeliver(orderShipDeliver));
    }

    /**
     * 修改订单发货信息
     */
    @PreAuthorize(hasPermi = "order:deliver:edit")
    @Log(title = "订单发货信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderShipDeliver orderShipDeliver) {
        return toAjax(orderShipDeliverService.updateOrderShipDeliver(orderShipDeliver));
    }

    /**
     * 删除订单发货信息
     */
    @PreAuthorize(hasPermi = "order:deliver:remove")
    @Log(title = "订单发货信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deliverUids}")
    public AjaxResult remove(@PathVariable Long[] deliverUids) {
        return toAjax(orderShipDeliverService.deleteOrderShipDeliverByIds(deliverUids));
    }


}
